<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      var getPromise = (value, delay) => {
        return new Promise((resolve) => {
          // setTimeout(function(){resolve(value)}, delay);//ES5 写法
          setTimeout(() => resolve(value), delay);//ES6 箭头函数写法
        });
      };
      var promise1 = getPromise('value-1', 3000);
      var promise2 = getPromise('value-2', 2000);
      var promise3 = getPromise('value-3', 1000);

      //Promise的静态方法 all
      var promise = Promise.all([promise1, promise2, promise3]);

      promise
        .then((result) => {
          console.log('result of promise:', result);
        })
        .catch((error) => {
          console.log('error', error);
        });

        // 3s之后才返回result of promise: (3) ['value-1', 'value-2', 'value-3']
        
    </script>
  </body>
</html>
